package com.lys.demo.web.support;

import java.util.HashMap;
import java.util.Map;

import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * http的状态code返回的是200
 * 
 * 可以根据不同的业务返回不同的异常在这里捕获，然后处理封装返回的json消息
 * @author liyinsong
 *
 */
@RestControllerAdvice
public class ExceptionHandlerController {

	@ExceptionHandler(RuntimeException.class)
	@ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR)
	public Map<String, Object> handleException(RuntimeException exception) {
		
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("result", "fail");
		result.put("errMsg", exception.getMessage());
		
		return result;
	}
	
//	@ExceptionHandler(****.class)
//	@ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR)
//	public Map<String, Object> handleException(RuntimeException exception) {
//		
//		Map<String, Object> result = new HashMap<String, Object>();
//		result.put("result", "fail");
//		result.put("errMsg", exception.getMessage());
//		
//		return result;
//	}
}
